<template>
  <div>
    <el-container>
      <el-main>
        <el-container class="parent-body">
          <el-header class="content-header">
            <div>发货列表</div>
            <div>
              <el-button icon="el-icon-arrow-left" @click.native="returnButton">返回</el-button>
            </div>
          </el-header>
          <el-main class="info-main padding-style">
            <el-table   ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                border
                style="width: 100%"
                @selection-change="handleSelectionChange">
                 <el-table-column type="selection" width="55" align="center"></el-table-column>
              <el-table-column prop="transactionId" label="订单编号" width="150"></el-table-column>
              <el-table-column prop="receiverContact" label="收货人"></el-table-column>
              <el-table-column prop="receiverMobile" label="手机号码"></el-table-column>
              <!-- 暂时没有这个字段 -->
              <el-table-column prop="postNumber" label="邮政编码"></el-table-column>
              <el-table-column prop="receiverAddress" label="收货地址"> </el-table-column>
              <el-table-column label="配送方式" width="200">
                <template slot-scope="scope">
                  <el-select  v-model="scope.row.shippingName" placeholder="请选择物流公司">
                 <el-option label="圆通" value="圆通"></el-option>
                <el-option label="菜鸟" value="菜鸟"></el-option>
                 <el-option label="申通" value="申通"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="shippingCode" label="物流单号" width="200">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.shippingCode"></el-input>
                </template>
              </el-table-column>
            </el-table>
          </el-main>
          <el-footer class="info-foot">
            <el-button  size="mini" @click.native="returnButton">取 消</el-button>
            <el-button  size="mini" @click.native="configButton(tableData)" type="primary">确 定</el-button>
          </el-footer>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>

<script>

   import orderListApi from "@/api/order/orderlist";
    export default {
        data() {
            return {
                tableData: [],
                  multipleSelection: [],
                  // 临时存储需要修改的数据
                  updateform:{
                    id:'',
                    shippingName:'',
                    shippingCode:'',
                    orderStatus:2,
                  },
             
            }
        },
        methods:{
            returnButton(){
                this.$router.replace({ path: "/order/orderList" });
            },
// 获取选中的数据
             handleSelectionChange(val) {
      // 因为此方法是在选择改变时调用，所以必须初始化数组 如果不初始化数组 数组将会层层叠加
      this.multipleSelection = [];
      
      // 为multipleSelection赋值   multipleSelection为id数组
      val.forEach(v => {
     this.updateform={};
        this.updateform.id=v.id;
        this.updateform.shippingName=v.shippingName;
        this.updateform.shippingCode=v.shippingCode;
        this.updateform.orderStatus=2;
        this.multipleSelection[this.multipleSelection.length] = this.updateform;
      });
    },
            // 获取到数据list
            configButton(){



              var data=JSON.parse(JSON.stringify(this.multipleSelection))
              console.log(data);

              data.forEach(v=>{
orderListApi.updateOne(v).then(respone=>{

  console.log(respone);
})
                
              });

           this.$router.go(0);


// 批量修改 传输数据有问题
            // orderListApi.updateAll(data).then(response=>{
            //   console.log(response);
            // })

            },

            intData(){
              orderListApi.selectByStatus().then(response=>{

                console.log(response);
                   this.tableData = response.data.data;
              })
            }
        },
        mounted(){
          this.intData();
        }
    }
</script>
<style scoped>
  .content-header{
    border-bottom:1px solid #E4E4E4;
    position: relative;
  }
  .parent-body{
    border:1px solid #E4E4E4;
  }
  .content-header{
    height:50px;
    line-height: 50px;
    background-color:#F3F3F3;
    color:#666666;
    position: relative;
    text-align: left;
  }
  .info-main{
    background-color:#fff;
  }

  .content-header>div{
    display: inline-block;
  }
  .content-header>div:last-of-type{
    position: absolute;
    right:10px;
  }
  .padding-style{
    padding:0 !important;
  }

  .info-foot{
    background-color:#FDFDFE;
    height:60px;
    line-height: 60px;
    position: relative;
    text-align: center;
  }
</style>
